class XP_Utils_Join_List:
  def __init__(self):
        pass

  @classmethod
  def INPUT_TYPES(cls):
      return {"required":
            {
              "strlist": ('LIST', {"forceInput": True}),
              "delimiter": ('STRING', {"default": ","}),
            },
            "optional": {
                "exclude": ('STRING', {"default": ""}),
                "search": ('STRING', {"default": ""}),
                "prefix": ('STRING', {"default": ""}),
                "suffix": ('STRING', {"default": ""}),
                "remove_empty": ("BOOLEAN", {"default": False}),
                "remove_duplicates": ("BOOLEAN", {"default": False}),
            }
          }

  RETURN_TYPES = ("STRING",)
  RETURN_NAMES = ("jonString",)
  OUTPUT_NODE = True
  FUNCTION = "sample"
  CATEGORY = "XP_Utils"

  def sample(self, strlist, delimiter=",", exclude="",search="", prefix="", suffix="",remove_empty=False, remove_duplicates=False):
    if len(strlist) == 0:
      return ("",)

    if not isinstance(strlist[0], str):
      raise Exception("List must contain strings.")

    # Remove empty strings if specified
    if remove_empty:
      strlist = [s for s in strlist if len(s)>0]

    # Remove duplicates if specified
    if remove_duplicates:
      strlist = list(dict.fromkeys(strlist))

    if search and isinstance(search, str):
      strlist = [s for s in strlist if search in s]

    if exclude and isinstance(exclude, str):
      strlist = [s for s in strlist if exclude not in s]

    if not strlist:
      return ("",)

    # add prefix and suffix to each string in the list
    newList = []
    for s in strlist:
      newList.append(prefix + s + suffix)
    return (delimiter.join(newList),)